package xionglizhen.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import xionglizhen.entity.Medicine;
import xionglizhen.mapper.MedicineMapper;
import xionglizhen.util.Assert;

import java.util.ArrayList;
import java.util.List;

@Service
public class MedicineService extends ServiceImpl<MedicineMapper, Medicine> {
    public List<Medicine> findMedicineByName(String medicineName,Integer currentPage,Integer pageSize) {
        List<Medicine> list = new ArrayList<>();

        if (Assert.isEmpty(medicineName)) {
            Page<Medicine> medicineList = new Page<>();
            IPage page1 = this.page(medicineList);
            list = page1.getRecords();
        }
        else {
            QueryWrapper<Medicine> queryWrapper = new QueryWrapper<>();
            queryWrapper.like(medicineName != null, "medicine_name", medicineName);
            list = this.baseMapper.selectList(queryWrapper);

        }

        return list;
    }
}
//, int pageSize, int curPage
//curPage, pageSize